<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- Copyright © 1988-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<title>Alias analysis (GNU Compiler Collection (GCC) Internals)</title>

<meta name="description" content="Alias analysis (GNU Compiler Collection (GCC) Internals)">
<meta name="keywords" content="Alias analysis (GNU Compiler Collection (GCC) Internals)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Option-Index.html" rel="index" title="Option Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Tree-SSA.html" rel="up" title="Tree SSA">
<link href="Memory-model.html" rel="next" title="Memory model">
<link href="SSA.html" rel="prev" title="SSA">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
span:hover a.copiable-link {visibility: visible}
ul.mark-bullet {list-style-type: disc}
-->
</style>


</head>

<body lang="en">
<div class="section-level-extent" id="Alias-analysis">
<div class="nav-panel">
<p>
Next: <a href="Memory-model.html" accesskey="n" rel="next">Memory model</a>, Previous: <a href="SSA.html" accesskey="p" rel="prev">Static Single Assignment</a>, Up: <a href="Tree-SSA.html" accesskey="u" rel="up">Analysis and Optimization of GIMPLE tuples</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h3 class="section" id="Alias-analysis-1"><span>13.4 Alias analysis<a class="copiable-link" href="#Alias-analysis-1"> &para;</a></span></h3>
<a class="index-entry-id" id="index-alias"></a>
<a class="index-entry-id" id="index-flow_002dsensitive-alias-analysis"></a>
<a class="index-entry-id" id="index-flow_002dinsensitive-alias-analysis"></a>

<p>Alias analysis in GIMPLE SSA form consists of two pieces.  First
the virtual SSA web ties conflicting memory accesses and provides
a SSA use-def chain and SSA immediate-use chains for walking
possibly dependent memory accesses.  Second an alias-oracle can
be queried to disambiguate explicit and implicit memory references.
</p>
<ol class="enumerate">
<li> Memory SSA form.

<p>All statements that may use memory have exactly one accompanied use of
a virtual SSA name that represents the state of memory at the
given point in the IL.
</p>
<p>All statements that may define memory have exactly one accompanied
definition of a virtual SSA name using the previous state of memory
and defining the new state of memory after the given point in the IL.
</p>
<div class="example smallexample">
<pre class="example-preformatted">int i;
int foo (void)
{
  # .MEM_3 = VDEF &lt;.MEM_2(D)&gt;
  i = 1;
  # VUSE &lt;.MEM_3&gt;
  return i;
}
</pre></div>

<p>The virtual SSA names in this case are <code class="code">.MEM_2(D)</code> and
<code class="code">.MEM_3</code>.  The store to the global variable <code class="code">i</code>
defines <code class="code">.MEM_3</code> invalidating <code class="code">.MEM_2(D)</code>.  The
load from <code class="code">i</code> uses that new state <code class="code">.MEM_3</code>.
</p>
<p>The virtual SSA web serves as constraints to SSA optimizers
preventing illegitimate code-motion and optimization.  It
also provides a way to walk related memory statements.
</p>
</li><li> Points-to and escape analysis.

<p>Points-to analysis builds a set of constraints from the GIMPLE
SSA IL representing all pointer operations and facts we do
or do not know about pointers.  Solving this set of constraints
yields a conservatively correct solution for each pointer
variable in the program (though we are only interested in
SSA name pointers) as to what it may possibly point to.
</p>
<p>This points-to solution for a given SSA name pointer is stored
in the <code class="code">pt_solution</code> sub-structure of the
<code class="code">SSA_NAME_PTR_INFO</code> record.  The following accessor
functions are available:
</p>
<ul class="itemize mark-bullet">
<li><code class="code">pt_solution_includes</code>
</li><li><code class="code">pt_solutions_intersect</code>
</li></ul>

<p>Points-to analysis also computes the solution for two special
set of pointers, <code class="code">ESCAPED</code> and <code class="code">CALLUSED</code>.  Those
represent all memory that has escaped the scope of analysis
or that is used by pure or nested const calls.
</p>
</li><li> Type-based alias analysis

<p>Type-based alias analysis is frontend dependent though generic
support is provided by the middle-end in <code class="code">alias.cc</code>.  TBAA
code is used by both tree optimizers and RTL optimizers.
</p>
<p>Every language that wishes to perform language-specific alias analysis
should define a function that computes, given a <code class="code">tree</code>
node, an alias set for the node.  Nodes in different alias sets are not
allowed to alias.  For an example, see the C front-end function
<code class="code">c_get_alias_set</code>.
</p>
</li><li> Tree alias-oracle

<p>The tree alias-oracle provides means to disambiguate two memory
references and memory references against statements.  The following
queries are available:
</p>
<ul class="itemize mark-bullet">
<li><code class="code">refs_may_alias_p</code>
</li><li><code class="code">ref_maybe_used_by_stmt_p</code>
</li><li><code class="code">stmt_may_clobber_ref_p</code>
</li></ul>

<p>In addition to those two kind of statement walkers are available
walking statements related to a reference ref.
<code class="code">walk_non_aliased_vuses</code> walks over dominating memory defining
statements and calls back if the statement does not clobber ref
providing the non-aliased VUSE.  The walk stops at
the first clobbering statement or if asked to.
<code class="code">walk_aliased_vdefs</code> walks over dominating memory defining
statements and calls back on each statement clobbering ref
providing its aliasing VDEF.  The walk stops if asked to.
</p>
</li></ol>


</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Memory-model.html">Memory model</a>, Previous: <a href="SSA.html">Static Single Assignment</a>, Up: <a href="Tree-SSA.html">Analysis and Optimization of GIMPLE tuples</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
